[mysql] subquery and update

I wanto set next max number from 'number' field +1 when I update any
record. I tryied to do like this:

UPDATE table set number=(select MAX(number)+1 from table) WHERE Id=122

but I got error 1093

How can I do it? It can't be autoincrement. I must be sure if nobody
else got the same number in the same time.
piotr [ Di, 02 Mai 2006 15:19 ] [ ID #1297909 ]

Re: [mysql] subquery and update

Piotr wrote:
> I wanto set next max number from 'number' field +1 when I update any
> record. I tryied to do like this:
>
> UPDATE table set number=(select MAX(number)+1 from table) WHERE Id=122
>
> but I got error 1093
>
> How can I do it? It can't be autoincrement. I must be sure if nobody
> else got the same number in the same time.

Which version of MySQL?

You could try

SET [at] new=(SELECT MAX(t.number) FROM table t); UPDATE table SET VALUE=(SELECT
[at] new := [at] new+1) WHERE ID=1;



//Aho
Shion [ Di, 02 Mai 2006 17:06 ] [ ID #1297913 ]
PHP » alt.php.sql » [mysql] subquery and update

Vorheriges Thema: Moving a db field
Nächstes Thema: need help w/ outputting to a textarea